<?php

namespace App\Http\Middleware;

use Closure;

class MustBeUser {
	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next) {
		if (!$request->session()->get('user')) {
			abort(401);
		} else {
			$user = $request->session()->get('user');
			if (!$user->is_admin && !count($user->business)) {
				abort(401);
			}
		}
		return $next($request);
	}
}
